package com.yiwei.zhh.api.requestInfo;

import com.yiwei.zhh.api.Api;
import com.yiwei.zhh.api.bean.DealDetailBean;
import com.yiwei.zhh.api.callback.MyFundContract;
import com.yiwei.zhh.util.Network;
import com.yiwei.zhh.util.RxLifeUtil;
import com.yiwei.zhh.util.ToastUtil;

/**
 * Created by Administrator on 2017/5/14.
 */

public class MyFundRequest extends BaseRequest<MyFundContract.View> implements MyFundContract.Presenter<MyFundContract.View> {

    public static MyFundRequest create() {
        return new MyFundRequest();
    }


    @Override
    public void getMyFund() {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        Api.api_service.getMyFund().compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getMyFundSuccess(1, result);
                });
    }

    public void getMyFund(int page, int pageSize) {
        if (!Network.checkNetwork(BaseContext)) {
            ToastUtil.makeText(BaseContext, networkFail).show();
            return;
        }
        mView.onRequestStart();
        DealDetailBean bean = new DealDetailBean();
        bean.pagesize = pageSize;
        bean.page = page;
        Api.api_service.getMyFund(bean).compose(RxLifeUtil.checkOn(BaseContext)).
                doFinally(() -> {
                    try {
                        mView.complete();
                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    mView.getMyFundSuccess(page, result);
                });
    }

}
